home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\SOURCE\IRCSIG.C < prev    next >
C/C++ Source or Header  |  1994-12-28  |  1KB  |  60 lines

  1. /*
  2.  * ircsig.c: has a `my_signal()' that uses sigaction().
  3.  *
  4.  * written by matthew green, 1993.
  5.  *
  6.  * i stole bits of this from w. richard stevens' `advanced programming
  7.  * in the unix environment' -mrg
  8.  */
  9.  
  10. #ifndef lint
  11. static    char    rcsid[] = "@(#)$Id: ircsig.c,v 1.3 1994/07/02 02:32:13 mrg Stab $";
  12. #endif
  13.  
  14. #include "irc.h"
  15. #include "irc_std.h"
  16.  
  17. #ifdef USE_SIGACTION
  18. sigfunc *
  19. my_signal(sig_no, sig_handler, misc_flags)
  20.     int sig_no;
  21.     sigfunc *sig_handler;
  22.     int misc_flags;
  23. {
  24.         /*
  25.          * misc_flags is unused currently.  it's planned to be used
  26.          * to use some of the doovier bits of sigaction(), if at
  27.          * some point we need them, -mrg
  28.          */
  29.  
  30.         struct sigaction sa, osa;
  31.  
  32.         sa.sa_handler = sig_handler;
  33.  
  34.         sigemptyset(&sa.sa_mask);
  35.         sigaddset(&sa.sa_mask, sig_no);
  36.  
  37.         /* this is ugly, but the `correct' way.  i hate c. -mrg */
  38.         sa.sa_flags = 0;
  39. #if defined(SA_RESTART) || defined(SA_INTERRUPT)
  40.         if (SIGALRM == sig_no)
  41.         {
  42. # if defined(SA_INTERRUPT)
  43.                 sa.sa_flags |= SA_INTERRUPT;
  44. # endif /* SA_INTERRUPT */
  45.         }
  46.         else
  47.         {
  48. # if defined(SA_RESTART)
  49.                 sa.sa_flags |= SA_RESTART;
  50. # endif /* SA_RESTART */
  51.         }
  52. #endif /* SA_RESTART || SA_INTERRUPT */
  53.  
  54.         if (0 > sigaction(sig_no, &sa, &osa))
  55.                 return (SIG_ERR);
  56.  
  57.         return (osa.sa_handler);
  58. }
  59. #endif /* USE_SIGACTION */
  60.